package com.mes.system.domain;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.Formula;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.JoinColumnOrFormula;
import org.hibernate.annotations.JoinColumnsOrFormulas;
import org.hibernate.annotations.JoinFormula;

import com.mes.basicdata.domain.Employee;
import com.mes.basicdata.domain.TypesData;
import com.mes.common.domain.BasicModel;

/**
 * MES系统发出的消息
 */
@Entity(name = "hxzz.mes.Message")
@Table(name = "S_MESSAGE")
public class Message extends BasicModel {
	public final static int MESSAGE_STATE_DRAFT = 0;
	public final static int MESSAGE_STATE_SEND = 1;
	public final static int MESSAGE_STATE_RECEIVED = 2;
	public final static int MESSAGE_STATE_END = 3;

	public static final int MESSAGE_PRIORITY_NORMAL = 1;
	public static final int MESSAGE_PRIORITY_IMPORTANT = 2;
	public static final int MESSAGE_PRIORITY_URGENT = 3;

	@Id
	@GenericGenerator(name = "messageUid", strategy = "assigned")
	@Column(name = "MESSAGEUID", length = 50)
	protected String messageUid;

	@Column(name = "MESSAGE_CONTENTUID", length = 50)
	protected String messageContentUid;
	// many-to-one
	@ForeignKey(name = "null")
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "MESSAGE_CONTENTUID", insertable = false, updatable = false)
	protected MessageContent messageContent;

	@Column(name = "PARENT_MESSAGEUID", length = 50)
	protected String parentMessageUid;

	@Column(name = "FROM_EMPLOYEEID", length = 50)
	protected String fromEmployeeUid;
	// many-to-one
	@ForeignKey(name = "null")
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "FROM_EMPLOYEEID", insertable = false, updatable = false)
	protected Employee fromEmployee;

	@Column(name = "TO_EMPLOYEEID", length = 50)
	protected String toEmployeeUid;
	// many-to-one
	@ForeignKey(name = "null")
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "TO_EMPLOYEEID", insertable = false, updatable = false)
	protected Employee toEmployee;

	@Column(name = "MESSAGESTATE", length = 10)
	protected Integer messageState;
	// many-to-one
	@ForeignKey(name = "null")
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumnsOrFormulas(value = {
			@JoinColumnOrFormula(column = @JoinColumn(name = "MESSAGESTATE", referencedColumnName = "ID", nullable = true, insertable = false, updatable = false)),
			@JoinColumnOrFormula(formula = @JoinFormula(value = "'messagestate'", referencedColumnName = "TYPESNAME")) })
	protected TypesData messageStateDesc;

	@Column(name = "MESSAGETYPE", length = 10)
	protected Integer messageType;
	// many-to-one
	@ForeignKey(name = "null")
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumnsOrFormulas(value = {
			@JoinColumnOrFormula(column = @JoinColumn(name = "MESSAGETYPE", referencedColumnName = "ID", nullable = true, insertable = false, updatable = false)),
			@JoinColumnOrFormula(formula = @JoinFormula(value = "'messagetype'", referencedColumnName = "TYPESNAME")) })
	protected TypesData messageTypeDesc;

	@Column(name = "MESSAGEPRIORITY", length = 10)
	protected Integer messagePriority;
	// many-to-one
	@ForeignKey(name = "null")
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumnsOrFormulas(value = {
			@JoinColumnOrFormula(column = @JoinColumn(name = "MESSAGEPRIORITY", referencedColumnName = "ID", nullable = true, insertable = false, updatable = false)),
			@JoinColumnOrFormula(formula = @JoinFormula(value = "'messagepriority'", referencedColumnName = "TYPESNAME")) })
	protected TypesData messagePriorityDesc;

	@Column(name = "SENDTIME", length = 7)
	protected Date sendTime;

	@Column(name = "RECEIVETIME", length = 7)
	protected Date receiveTime;

	@Formula("(select count(*) from f_file_field fff where fff.fielduid=MESSAGEUID  and fff.fieldType='MESSAGE_ATTACH_FILE')")
	protected Integer attachFileCount;

	@Override
	public String getUuid() {
		// TODO Auto-generated method stub
		return this.getMessageUid();
	}

	@Override
	public void setUuid(String uuid) {
		// TODO Auto-generated method stub
		this.setMessageUid(uuid);
	}

	public String getMessageUid() {
		return messageUid;
	}

	public void setMessageUid(String messageUid) {
		this.messageUid = messageUid;
	}

	public String getParentMessageUid() {
		return parentMessageUid;
	}

	public void setParentMessageUid(String parentMessageUid) {
		this.parentMessageUid = parentMessageUid;
	}

	public String getFromEmployeeUid() {
		return fromEmployeeUid;
	}

	public void setFromEmployeeUid(String fromEmployeeUid) {
		this.fromEmployeeUid = fromEmployeeUid;
	}

	public String getToEmployeeUid() {
		return toEmployeeUid;
	}

	public void setToEmployeeUid(String toEmployeeUid) {
		this.toEmployeeUid = toEmployeeUid;
	}

	public String getMessageContentUid() {
		return messageContentUid;
	}

	public void setMessageContentUid(String messageContentUid) {
		this.messageContentUid = messageContentUid;
	}

	public Integer getMessageState() {
		return messageState;
	}

	public void setMessageState(Integer messageState) {
		this.messageState = messageState;
	}

	public TypesData getMessageStateDesc() {
		return messageStateDesc;
	}

	public void setMessageStateDesc(TypesData messageStateDesc) {
		this.messageStateDesc = messageStateDesc;
	}

	public Integer getMessageType() {
		return messageType;
	}

	public void setMessageType(Integer messageType) {
		this.messageType = messageType;
	}

	public TypesData getMessageTypeDesc() {
		return messageTypeDesc;
	}

	public void setMessageTypeDesc(TypesData messageTypeDesc) {
		this.messageTypeDesc = messageTypeDesc;
	}

	public Integer getMessagePriority() {
		return messagePriority;
	}

	public void setMessagePriority(Integer messagePriority) {
		this.messagePriority = messagePriority;
	}

	public TypesData getMessagePriorityDesc() {
		return messagePriorityDesc;
	}

	public void setMessagePriorityDesc(TypesData messagePriorityDesc) {
		this.messagePriorityDesc = messagePriorityDesc;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public Date getSendTime() {
		return sendTime;
	}

	public void setSendTime(Date sendTime) {
		this.sendTime = sendTime;
	}

	public Date getReceiveTime() {
		return receiveTime;
	}

	public void setReceiveTime(Date receiveTime) {
		this.receiveTime = receiveTime;
	}

	public String getNotes() {
		return notes;
	}

	public void setNotes(String notes) {
		this.notes = notes;
	}

	public Employee getFromEmployee() {
		return fromEmployee;
	}

	public void setFromEmployee(Employee fromEmployee) {
		this.fromEmployee = fromEmployee;
	}

	public Employee getToEmployee() {
		return toEmployee;
	}

	public void setToEmployee(Employee toEmployee) {
		this.toEmployee = toEmployee;
	}

	public MessageContent getMessageContent() {
		return messageContent;
	}

	public void setMessageContent(MessageContent messageContent) {
		this.messageContent = messageContent;
	}

	public Integer getAttachFileCount() {
		return attachFileCount;
	}

	public void setAttachFileCount(Integer attachFileCount) {
		this.attachFileCount = attachFileCount;
	}

}
